//check login
$(document).ready(function(){
    
    var name=localStorage.getItem("name");
    var password=localStorage.getItem("password");
    if(name!=""&&password!=""){
        const Url='http://124.71.207.55:8081/userLogin/'+name+'/'+password;
        $.ajax({
            url: Url,
            type: "POST",
            success:function(result){
                console.log(result);
                if(result=="登录成功"){
                    $.ajax({
                        url : 'http://124.71.207.55:8081/getAccessByName/'+name,
                        type: 'GET',
                        success:function(access){
                          if(window.location.pathname!='/shop.html' && access==1){
                            location.href=("shop.html");
                          }else if(window.location.pathname=='/shop.html' && access==0){
                            location.href=("index.html");
                          }
                        }
                      })
                  }else{
                    localStorage.setItem("name", "");
                    localStorage.setItem("password", "");
                    location.href=("login.html");
                  }
            }
        })
    }else{
        localStorage.setItem("name", "");
        localStorage.setItem("password", "");
        location.href=("login.html");
    }
})